package com.yanqu.road.server.cmd.activity.celebration;

import com.yanqu.road.pb.celebration.CelebrationProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.celebration.CelebrationMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.CrossProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @Description 庆典进入活动
 * @Author cwq
 * @Data 2021/7/12 16:08
 */
@Cmd(code = GameProtocol.S_CELEBRATION_DATA, desc = "进入活动")
public class CelebrationEnterActivityCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        CelebrationProto.CelebrationGetProgressReqMsg reqMsg = CelebrationProto.CelebrationGetProgressReqMsg.parseFrom(packet.getBytes());
        ret = CelebrationMgr.canEnterActivity(player,reqMsg.getActivityId());
        if(ret != 0){
            return;
        }
        player.sendPacket(CrossProtocol.C2_CELEBRATION_DATA, reqMsg.toBuilder());
    }

    @Override
    public void sendData(GamePlayer player) {
        if (ret != 0) {
            CelebrationProto.CelebrationGetProgressRespMsg.Builder builder = CelebrationProto.CelebrationGetProgressRespMsg.newBuilder();
            builder.setRet(ret);
            player.sendPacket(ClientProtocol.U_CELEBRATION_DATA, builder);
        }
    }
}
